﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Data
{
    public class StarSystem
    {
        #region Attributes
        private Guid starId;
        private Guid masterStarId;

        private Dictionary<Guid, MasterWarpPoint> masterWpList = new Dictionary<Guid, MasterWarpPoint>();
        private Dictionary<Guid, WarpPoint> wpList = new Dictionary<Guid, WarpPoint>();

        private string name;
        private string owner;
        #endregion

        #region Properties
        public Guid StarId
        {
            get { return starId; }
        }
        public Guid MasterStarId
        {
            get { return masterStarId; }
        }
        public bool IsMaster
        {
            get { return masterStarId == Guid.Empty; }
        }
        public string Name
        {
            get { return name; }
            set { name = value; }
        }
        public string Owner
        {
            get { return owner; }
            set { owner = value; }
        }
        #endregion

        #region Constructors
        public StarSystem()
        {
            starId = Guid.NewGuid();
            masterStarId = Guid.Empty;
        }
        public StarSystem(Guid master)
        {
            starId = Guid.NewGuid();
            masterStarId = master;
        }
        #endregion

        public MasterWarpPoint GetWarpPoint(Guid id)
        {
            if (!masterWpList.ContainsKey(id))
                return null;

            return masterWpList[id];
        }
        public Dictionary<Guid, MasterWarpPoint> MasterWpList()
        {
            return masterWpList;
        }

        public Guid CreateWarpPoint(Guid destination, MapIndex location, string name)
        {
            MasterWarpPoint newWp = new MasterWarpPoint(destination, name);
            newWp.Location = location;

            masterWpList.Add(newWp.WarpPointId, newWp);

            return newWp.WarpPointId;
        }

        internal MasterWarpPoint GetMWPDeails(Guid masterId)
        {
            if (! masterWpList.ContainsKey(masterId))
                return null;

            return masterWpList[masterId];
        }
    }
}
